export default class ArrayUtils {
    
    static updateArray(array, item){
        for (var i = 0; i < array.length; i++) {
            var temp = array[i];
            if(temp === item){
                array.splice(i, 1);
                return;
            }
        }
        array.push(item);
    }
    
    static clone(array){
        if(!array) return [];
        let newArray = [];
        for (let i = 0; i < array.length; i++) {
            newArray[i] = array[i];
        }
        return newArray;
    }

    static isEqual(arr1, arr2){
        if(!(arr1 && arr2)) return false;
        if(arr1.length !== arr2.length) return false;
        for (let i = 0; i < arr1.length; i++) {
            if(arr1[i] !== arr2[i]) return false;
        }
        return true;
    }

    static remove(arr, item){
        if(!arr) return;
        for (let i = 0; i < arr.length; i++) {
            if (item === arr[i]) arr.splice(i,1);
        }
    }
}